<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- Import style -->
    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
    <!-- Import Vue 3 -->
    <script src="//unpkg.com/vue@3"></script>
    <!-- Import component library -->
    <script src="http://unpkg.com/element-plus"></script>

    <link rel="stylesheet" href="./css/grade.css">
</head>

<body>
    <div id="app">
        <el-card style="max-width: 480px" v-for="student in students">
            <div class="card-header">
                <span><el-avatar :size="50" :src="student.avatar" /></span>
                <span>{{ student.name }}</span>
            </div>
            <div>
                <hr>
                <p>年龄：{{ student.age }}</p>
                <p>性别：{{ student.sex }}</p>
                <p>总分：{{ student.score[0] + student.score[1] + student.score[2]}}</p>
                <hr>
            </div>
            <el-tooltip effect="dark" placement="bottom"
                v-if="student.score[0]>=60&&student.score[1]>=60&&student.score[2]>=60">
                <template #content>
                    <p>语文：{{student.score[0]}}</p><br />
                    <p>数学：{{student.score[1]}}</p><br />
                    <p>英语：{{student.score[2]}}</p><br />
                </template>
                <el-button>查看成绩单</el-button>
            </el-tooltip>
        </el-card>

        <div>
            <el-button type="primary" @click="drawer=true">新增</el-button>
        </div>
        <el-drawer v-model="drawer" title="新增学生成绩单" :with-header="false">
            <!-- 姓名：
            年龄：
            性别：
            语文：
            数学：
            英语：
            提交按钮，绑定事件 -->
            <el-form :model="form" label-width="auto" class="form" style="max-width: 600px">
                <el-form-item label="姓名">
                    <el-input v-model="form.name" />
                </el-form-item>
                <el-form-item label="年龄">
                    <el-input v-model="form.age" />
                </el-form-item>
                <el-form-item label="性别">
                    <el-radio-group v-model="form.sex">
                        <el-radio value="保密">保密</el-radio>
                        <el-radio value="男">男</el-radio>
                        <el-radio value="女">女</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="语文">
                    <el-input-number v-model="form.score[0]" class="mx-4" />
                </el-form-item>
                <el-form-item label="数学">
                    <el-input-number v-model="form.score[1]" class="mx-4" />
                </el-form-item>
                <el-form-item label="英语">
                    <el-input-number v-model="form.score[2]" class="mx-4" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="onSubmit">提交</el-button>
                </el-form-item>
            </el-form>


        </el-drawer>
    </div>
</body>
<script>
    const info = {
        data() {
            return {
                students: [
                    {  name: '张三', age: 20, sex: '男', score: [70, 80, 90], avatar: './img/avatar' + Math.floor(Math.random() * 10) + ".png" },
                    {  name: '李四', age: 20, sex: '男', score: [60, 70, 80], avatar: './img/avatar' + Math.floor(Math.random() * 10) + ".png" },
                    {  name: '王五', age: 20, sex: '男', score: [80, 90, 100], avatar: './img/avatar' + Math.floor(Math.random() * 10) + ".png" },
                ],
                drawer: false,
                form: {  name: '', age: 0, sex: '男', score: [0, 0, 0], avatar: './img/avatar' + Math.floor(Math.random() * 10) + ".png" },
            }
        },
        methods: {
            onSubmit() {
                this.students.push(this.form);
                this.drawer = false;
                this.form = {  name: '', age: 0, sex: '男', score: [0, 0, 0], avatar: './img/avatar' + Math.floor(Math.random() * 10) + ".png" };
            }
        }
    }
    Vue.createApp(info).use(ElementPlus).mount("#app")
</script>

</html>